/*-------------------------------------------------------------------------

***************** Modification History ***********************************
   @doc
   @module operate.c - Operation functions |
   @end

$Log: /SoftPay/SPK2SIM/Source/Main/operate.c $

**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#define VSOPER_C

#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <applidl.h>
#include <acldev.h>
#include <svctxo.h>
#include <dbmgr.h>
#include <project.h>
#include <string.h>
#include <txoinc.h>
#include <aclstr.h>
#include <svc.h>
#include <varrec.h>

/* VeriFind Support */
//#include <beetle.h>
//#include <beetleplug.h>

/** /#define DEBUG_VSOPER */
#ifdef DEBUG_VSOPER
#define DEBUG_95
#endif


#include <define.h>
#include <transact.h>
#include <oper.h>
#include <comm.h>
#include <gds.h>
#include <fct.h>
#include <accum.h>
#include <date.h>
#include <menufunc.h>
#include <ui.h>
#include <msg.h>
#include <msgfuncs.h>
#include <hdt.h>
#include <opt.h>
#include <tct.h>
#include <table.h>
#include <tran.h>
#include <spdebug.h>
#include <pform.h>
#include <settle.h>
#include <operate.h>
#include <pbatch.h>
#include <entry.h>
#include <lct.h>
#include <tblutil.h>
#include <cdt.h>
#include <confio.h>
#include <passwd.h>
#include <pcheck.h>
#include <trt.h>
#include <opedit.h>
#include <report.h>
#include <mit.h>
#include <codesec.h>
#include <logo.h>
#include <xmodem.h>
#include <modemmsg.h>
#include <mdlfuncs.h>
#include <pct.h>
#include <funcs.h>
#include <mem.h>
#include <test.h>
#include <init.h>
#include <pscalls.h>
#include <menus.h>
#include <mbtx3.h>

extern char* pchGetMessage(long);
extern const long _heapsize;
extern const long _stacksize;

extern int trancount;

int inFullDownloadOperation(TRANSACTION_OBJECT* pobTran) {
    int inResult;
    extern int errno;
    extern int hConsoleS;

    /** /pdebug(("--inFullDownloadOperation--"));*/

    if (fGetDemoMode() == VS_TRUE) {
        vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
        return (VS_ERR);
    }

    if ((fChkAllHostBatches(pobTran) == VS_FALSE) || (fOpenTabEmpty(pobTran) == VS_FALSE)) {
        vdDisplayMessageFromFile(BATCH_NOT_EMPTY_ERR_MSG15, ERROR_MSG);
        return (VS_ERR);
    }

    vdDisplayMessageFromFile(LAN_WAIT_ERR_MSG, STATUS_MSG);

    inResult = inCallZontalk('F');

    if (inResult < 0)
        SVC_RESTART("SP2000.OUT");

    return (VS_SUCCESS);
}

int inPartDownloadOperation(TRANSACTION_OBJECT* pobTran) {
    int inResult;

    /** /pdebug(("--inPartDownloadOperation--"));*/

    if (fGetDemoMode() == VS_TRUE) {
        vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
        return (VS_SUCCESS);
    }

    if ((fChkAllHostBatches(pobTran) == VS_FALSE) || (fOpenTabEmpty(pobTran) == VS_FALSE)) {
        vdDisplayMessageFromFile(BATCH_NOT_EMPTY_ERR_MSG15, ERROR_MSG);
        return (VS_ERR);
    }

    vdDisplayMessageFromFile(LAN_WAIT_ERR_MSG, STATUS_MSG);
    inResult = inCallZontalk('P');

    SVC_RESTART("SP2000.OUT");

    return(inResult);
}

/*-------------------------------------------------------------------------
    Function :  vdDisplayNoSettleMsg()
    Description : Displays Settlement not allowed because of Demo Mode
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0    10/08/96 Jim_B4     Creation
--------------------------------------------------------------------------*/

void vdDisplayNoSettleMsg(long    lnMsgID) {
    char szDisplayBuffer[DISP_STR_LEN + 1];

    vdGetMessageFromFile(SETTLEMENT_NOT_ALLOW_MSG, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol + 1, obDisp.inDetailLine, szDisplayBuffer, CLR_EOL);
    vdGetMessageFromFile(lnMsgID, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol + 1, obDisp.inInputLine, szDisplayBuffer, CLR_EOL);
    vdGetMessageFromFile(CLEAR_TO_CONTINUE_MSG, szDisplayBuffer);
    vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, szDisplayBuffer, CLR_EOL);
    get_char();
}

/*-------------------------------------------------------------------------
    Function :  inLockOperation()
    Description : Keyboard Lock operation
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1    04/23/96 Paula_J1  Lock keyboard with supervisor level password
--------------------------------------------------------------------------*/

int inLockOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inLockOperation--"));*/

    if (inGetPwdFromUser(ACCESS_WITH_SUPER_PASSWORD, NO_PIT_INDEX) != VS_ESCAPE) {
        if (inLoadTCTRec(0) != VS_SUCCESS) {
            vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
            return(VS_ERROR);
        }
        vdSetKeyboardLock(VS_TRUE);
        if (inSaveTCTRec(0) != VS_SUCCESS) {
            vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
            return(VS_ERROR);
        }
    }
    return(BRANCH_EXIT);
}

/*-------------------------------------------------------------------------
    Function :  inAboutFileProcessing()
    Description : About File Processing Functionality

    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   01/07/98 Paula_J1   Creation...
      1   01/28/98 Kevin_V1   Modified to allow up to three lines of text
                              to be read from About.Txt ':' seperated.
      2   02/06/98 Paula_J1   Modified for O470 multi lines display (2 sec.delay) .
--------------------------------------------------------------------------*/

int inAboutFileProcessing(TRANSACTION_OBJECT* pobTran) {
#ifndef IMAM_REMOVE
    char szMessage[(MESSAGE_SIZE*3)];
    char szDisplay[MESSAGE_SIZE];
    int inResult,
    inFldIdx,
    inRowOffset;
    int inTopLeftX,
    inTopLeftY,
    inBotRightX,
    inBotRightY;
    int inKey;
    char szCurFontFile[FILENAME_SIZE + 1];

    FHANDLE hFHandle;

    if ((hFHandle = open("about.txt", O_RDONLY)) < 0)
        return(VS_ERR);

    memset(szMessage, 0x00, sizeof(szMessage));

    inResult = read(hFHandle, szMessage, sizeof(szMessage));
    if (inResult == VS_ERROR)              /* Error reading record info */ {
        close(hFHandle);
        return(VS_ERR);
    }
    close(hFHandle);

    /*
     *      Strip text editor trash from the end of the file
     */
    while (szMessage[strlen(szMessage) - 1] < ' ')
        szMessage[strlen(szMessage) - 1] = NULL_CH;
    vdClearNonTitleLines();

    if (getgrid() == 0) // The display is in the 4x8 grid
    {
        get_font(szCurFontFile);
        wherewin(&inTopLeftX, &inTopLeftY, &inBotRightX, &inBotRightY);
        setfont(ASC8X21_VFT);

        for (inFldIdx = 1; inFldIdx <= 3; ++inFldIdx) {
            memset(szDisplay, 0, sizeof(szDisplay));
            fieldvar(szMessage, inFldIdx, ':', szDisplay);
            vdDisplayAt(obDisp.inHomeCol, inFldIdx + 3, szDisplay, NO_CLEAR);
        }
        window(inTopLeftX, inTopLeftY, inBotRightX, inBotRightY);
        setfont(szCurFontFile);
    } else {
        inRowOffset = (obDisp.inCharsPerColumn == 4 ? 1 : 3);
        for (inFldIdx = 1; inFldIdx <= 3; ++inFldIdx) {
            memset(szDisplay, 0, sizeof(szDisplay));
            fieldvar(szMessage, inFldIdx, ':', szDisplay);
            vdDisplayAt(obDisp.inHomeCol, inFldIdx + inRowOffset, szDisplay, NO_CLEAR);
        }
    }

    inKey = inWaitKey(inGetIdleTimeOut());

    if (fGetMegaPassword() && inKey != KEY_CLR && inKey != KEY_CANCEL) {
        struct fs_size srFS;
        char buffer[30];

        clrscr();
        dir_get_sizes("I:", &srFS);
        sprintf(buffer, "RAM SIZE   = %ld.", (srFS.InUse + srFS.Avail));
        vdDisplayAt(1, 1, buffer, NO_CLEAR);
        sprintf(buffer, "I: AVAIL   = %ld.", (srFS.Avail));
        vdDisplayAt(1, 2, buffer, NO_CLEAR);
        dir_get_sizes("F:", &srFS);
        sprintf(buffer, "FLASH SIZE = %ld.", (srFS.InUse + srFS.Avail));
        vdDisplayAt(1, 3, buffer, NO_CLEAR);
        sprintf(buffer, "F: AVAIL   = %ld.", (srFS.Avail));
        vdDisplayAt(1, 4, buffer, NO_CLEAR);
        sprintf(buffer, "HEAP SIZE  = %ld.", _heapsize);
        vdDisplayAt(1, 5, buffer, NO_CLEAR);
        sprintf(buffer, "MAX HEAP   = %ld.", _heap_max());
        vdDisplayAt(1, 6, buffer, NO_CLEAR);
        sprintf(buffer, "STACK SIZE = %ld.", _stacksize);
        vdDisplayAt(1, 7, buffer, NO_CLEAR);
        sprintf(buffer, "MAX STACK  = %ld.", _stack_max());
        vdDisplayAt(1, 8, buffer, NO_CLEAR);
        inWaitKey(inGetIdleTimeOut());
    }

    pdebug(("MAX Heap used = %ld.", _heap_max()));
    pdebug(("MAX Stack used = %ld.", _stack_max()));
#endif //IMAM_REMOVE
    return(BRANCH_EXIT);
} /* End of inAboutFileProcessing () */

/*---------------------------------------------------------------------------
    Function :    inDateTimeOperation()
    Description : This function obtains the system date
                  or time by prompting the user.

    Inputs :      pobTran
    Parameters :
    Returns :     BRANCH_EXIT
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------  ---------------------------------------------
      0   01/04/99 Erich_W1    Initial Revision.
----------------------------------------------------------------------------*/
int inDateTimeOperation(TRANSACTION_OBJECT* pobTran) {
    if (pobTran) {
        /*
         *  set the date
         */
        if (inEnterSysChron(pobTran, 0) != VS_SUCCESS)
            return(BRANCH_EXIT);
        /*
         *  set the time
         */
        if (inEnterSysChron(pobTran, 1) != VS_SUCCESS)
            return(BRANCH_EXIT);
    }

    return(BRANCH_EXIT);
}



/*---------------------------------------------------------------------------
    Function :    inDemoTrainOperation
    Description : This function checks mode (DEMO) - if set, prompts for clear
                  of demo/training batch, if not, checks to see if any transactions
                  are in batch.  If batch is empty, sets mode to DEMO, otherwise
                  prompts user that batches must be cleared before demo can
                  be turned on.
    Parameters :
    Returns :     VS_ERR, VS_ABORT or VS_SUCCESS
    Globals :     gds
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ----------  ---------------------------------------------
 ---------------------------------------------------------------------------*/

int inDemoTrainOperation(TRANSACTION_OBJECT* pobTran) {
    char szOn[MESSAGE_SIZE + 1],
    szOff[MESSAGE_SIZE + 1];
    char szDisplayBuffer[DISP_STR_LEN + 1],
    szHold[MESSAGE_SIZE + 1];

    int inRowLim = inGetRowLim();
    signed int inOnOffValue,
    inCurrentOnOffValue = fGetDemoMode();

    pdebug(("inDemoTrainOperation=%d", inCurrentOnOffValue));

    vdGetMessageFromFile(MSG_ON, szOn);
    vdGetMessageFromFile(MSG_OFF, szOff);

    memset(szHold, 0, sizeof(szHold));

    if (inCurrentOnOffValue)
        strcpy(szHold, szOn);
    else
        strcpy(szHold, szOff);

    memset(szDisplayBuffer, 0, sizeof(szDisplayBuffer));
    vdGetMessageFromFile(DEMO_MODE_MSG, szDisplayBuffer);

    inOnOffValue = obDisp.inDO_ChooseOne(szDisplayBuffer, szHold, (char *) pchGetMsg(ON_OFF_MSG5x), 2, NULL_PFI);
    inOnOffValue = (inOnOffValue == 1 ? inOnOffValue : 0);
    pdebug(("inOnOffValue=%d", inOnOffValue));

    if (inOnOffValue != inCurrentOnOffValue) {
        if ((fChkAllHostBatches(pobTran) == VS_FALSE) || (fOpenTabEmpty(pobTran) == VS_FALSE)) {
            if ((obDisp.inDO_ChooseOne((char *) pchGetMsg(BATCH_NOT_EMPTY_ERR_MSG15), (char *) pchGetMsg(BATCHCLEAR_MSG15), (char *) pchGetMsg(YESNO_MSG5x), 2, NULL_PFI)) != KEY_YES) {
                vdDisplayMessageFromFile(TXN_CANCELLED, ERROR_MSG);
                return(VS_ESCAPE);
            } else {
#ifdef BATCH_DEFINED
                if (inDeleteAllBatches(pobTran) != VS_SUCCESS)
                    return(VS_ERR);
#endif // BATCH_DEFINED
            }
        }
    }

    vdClearASCII8x21Window(1, 3, 21, 8);

    if (inOnOffValue == 1)      /* Turn Demo Mode ON */ {
        if (!inCurrentOnOffValue)  /* Ensure Demo Mode is OFF before changing */ {
            strcpy(szHold, szOn);
            vdSetDemoMode(1);
            if (inSaveTCTRec(0) != VS_SUCCESS) {
                vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
                return(VS_ERROR);
            }
            trancount = 0;
        }
        vdDispMsgCentered(DEMO_MODE_ON_MSG, obDisp.inInputLine + 1, CLR_EOL);
    } else if (inOnOffValue == 0) /* Turn Demo Mode OFF */ {
        if (inCurrentOnOffValue)   /* Ensure Demo Mode is ON before changing */ {
            strcpy(szHold, szOff);
            vdSetDemoMode(0);
            if (inSaveTCTRec(0) != VS_SUCCESS) {
                vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
                return(VS_ERROR);
            }
        }
        vdDispMsgCentered(DEMO_MODE_OFF_MSG, obDisp.inInputLine + 1, CLR_EOL);
    }

    vdDelay(PROMPT_DELAY);

    return(VS_SUCCESS);
}




/*---------------------------------------------------------------------------
    Function :    inLangSetOperation
    Description : This function set the default language in the TCT table.
    Parameters :
    Returns :     VS_ERR, VS_ABORT or VS_SUCCESS
    Globals :
    Notes :
 ---------------------------------------------------------------------------*/

int inLangSetOperation(TRANSACTION_OBJECT* pobTran) {
    int inNumChoices;
    char szLCTTemplateFileName[FILENAME_SIZE + 1];

    //pdebug(("-inLangSetOperation-"));

    /* prompt for the desired receipt language and set pobTran field */
    inNumChoices = inGetLCTTotRecs();
    if (inNumChoices == 1) {
        vdDisplayMessageFromFile(NO_2ND_LANG_MSG, ERROR_MSG);
        return(VS_SUCCESS);
    }
    if (inGetLanguageIndex(pobTran) == VS_ERR)
        return (VS_ERR);

    vdClearNonTitleLines();

    vdSetLanguageIdx(pobTran->srBRec.inLCTIndex);
    if (inSaveTCTRec(0) != VS_SUCCESS) {
        vdDisplayMessageFromFile(TCT_ERR_MSG21, ERROR_MSG);
        return(VS_ERR);
    }

    // KV1 20010117
    pobTran->inSaveTCTLanguage = inGetLanguageIdx();

    inGetDefaultLCT();
    vdValidateFontFileNames();
    vdUpdateKbdStatusMsg();

    // Select the template files for the printer also
    if (inGetPrinterType() != NOPRINTER) {
        inSelectTemplateFile(&obPrinter);
        inGetDefaultTemplateName(szLCTTemplateFileName);
        if (inOpenFormater(szLCTTemplateFileName, &obPrinter)) {
            vdSGErrorMessage(FORMATER_ERR_MSG);
            return (VS_ERR);
        }
    }

    return(VS_SUCCESS);
}


/*-------------------------------------------------------------------------
    Function : inInitOper
    Description : Sets the transaction type and get the display string
    Parameters : int - Transaction Type
    Returns : void
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      1   10/11/96 Page_K1    Clear srVF (Visa global data area)
      2   08/11/97 KC_C1      Add  CHECK_OPERATION
      3   01/14/98 Kevin_V1   Changed title display from vdDisplayTitle() to vdDisplayTranTitle().
      4   01/19/98 Betty_B1   To set inType to a non-zero value - see ITO 5
      5   03/18/98 Page_K1    Clear RCPT_FIELDS
      6   09/15/98 Page_K1    Initialize pobTran->srBRec.inLCTIndex
--------------------------------------------------------------------------*/

int inInitOper(int inOperationCode,int inSubOperationCode,TRANSACTION_OBJECT* pobTran) {
    char szDate[DATE_SIZE + 1],
    szTime[TIME_SIZE + 1];

    /** /pdebug (("--inInitOper--"));
        pdebug(("oper %d",inOperationCode));
        pdebug(("sub oper %d",inSubOperationCode));*/

    if (inLoadOPTRec(inOperationCode) != VS_SUCCESS) {
        vdDisplayMessageFromFile(OPERATION_NOT_SUPPORTED_MSG, ERROR_MSG);
        return(VS_ERR);
    }

    vdSGErrorMessage(0L); // Clear error message
    //memset(&srGDS, 0, GDS_SIZE);

    /*  memset(&srRcpt, 0, sizeof(RCPT_FIELDS));*/
    vdClearRcpt();

    vdGetDate(szDate, MMDDYY);  /* mb1 */
    strcpy(pobTran->srBRec.szDate, szDate);
    vdGetTime(szTime);
    strcpy(pobTran->srBRec.szTime, szTime);

    pobTran->srBRec.inType = ADMIN_TRAN;
    inSetDefaultLanguage(pobTran);

    vdSGOpCode(inOperationCode);  /* pj1 */
    /* DH1 - Now displaying transaction type (e.g. Sale) instead of Transaction */
    switch (inOperationCode) {
    case CARD_OPERATION:
    case HOST_OPERATION:
    case PREAUTH_OPERATION:
    case PRECOMP_OPERATION:
    case OPENTAB_DEL_OPERATION:
    case CHECK_OPERATION:
    case ADMIN_OPERATION:
        vdSGCode(inSubOperationCode);
        break;
    default:
        break;
    }

    return(VS_SUCCESS);
}

TRANSACTION_OBJECT* pstGet_pobTran(void) {
    int inResult;
    TRANSACTION_OBJECT* pobTran;

    pobTran = pstGetSet_pobTran((TRANSACTION_OBJECT *) NULL, 0, &inResult);
    /** /pdebug (("Get pob %x",pobTran));*/
    return ((TRANSACTION_OBJECT *) pobTran);
}


TRANSACTION_OBJECT* pstGetSet_pobTran(TRANSACTION_OBJECT* pstTranObject,int inMode,int* pinResult) {
    static TRANSACTION_OBJECT* s_pobTran = NULL;
    int inRetVal = VS_ERR;

    /*
     *      Mode 0 is GET Address
     */

    if (inMode == 0) {
        if (s_pobTran == NULL) {
            pdebug(("NULL Get"));
            vdSGErrorMessage(POBTRAN_USE_ERR_MSG21);
        } else
            inRetVal = VS_SUCCESS;
        /** /pdebug (("Get s_pob %x",s_pobTran));*/
    }
    /*
     *      Mode 1 is SET Address
     */
    else if (inMode == 1) {
        if (s_pobTran != NULL) {
            pdebug(("Not NULL Set"));
            vdSGErrorMessage(POBTRAN_USE_ERR_MSG21);
        } else {
            s_pobTran = pstTranObject;
            inRetVal = VS_SUCCESS;
        }
        if (s_pobTran == NULL) {
            pdebug(("NULL Set"));
            vdSGErrorMessage(POBTRAN_USE_ERR_MSG21);
            inRetVal = VS_ERR;
        }

        /** /pdebug (("Set s_pob %x",s_pobTran));*/
    }
    /*
     *      Mode 2 is CLEAR Address
     */
    else if (inMode == 2) {
        if (s_pobTran == NULL) {
            pdebug(("NULL Clear"));
            vdSGErrorMessage(POBTRAN_USE_ERR_MSG21);
        } else {
            s_pobTran = NULL;
            inRetVal = VS_SUCCESS;
        }
        /** /pdebug (("Clear s_pob %x",s_pobTran));*/
    }

    *pinResult = inRetVal;
    return s_pobTran;
} /* End of inGetSet_pobTran () */

/*-------------------------------------------------------------------------
    Function : inOperations
     Modification History :
       #     Date      Who                     Description
     ----- -------- ---------- ---------------------------------------------
--------------------------------------------------------------------------*/

int inOperations(int inOperationCode,int inSubOperationCode,long lnTranMsg) {
    int inResult;
    TRANSACTION_OBJECT obTran;


    /** /pdebug(("--inOperations--"));*/
    /** /pdebug (("ObTran = %x",&obTran));*/

    /* VeriFind Support */
    //BT_TRACE (' ', "Begin Transaction");

    pstGetSet_pobTran(&obTran, 1, &inResult);
    if (inResult == VS_ERR)
        return VS_ERR;

    /*
     * This code must be compiled in even though we are not using the base batch
     * otherwise it will fail later on due to uninitialised pointers.
     */
    //#ifdef BATCH_DEFINED
    memset((char *) &obTran, 0x00, sizeof(TRANSACTION_OBJECT));
    if (inInitBatchStructures(&obTran.srBKey, &obTran.srBRec) != VS_SUCCESS)
        return VS_ERR;
    //#endif

    if ((obTran.pchFlexiData = (unsigned char *) pchAlloc(MAX_TRAN_FLEXI_REC_SIZE)) == NULL_CH) {
        vdFree((char *) obTran.srBRec.pchHostData);
        pdebug(("Tran Flexi Alloc Fail"));
        return VS_ERR;
    }

    vVarInitRecord(obTran.pchFlexiData, MAX_TRAN_FLEXI_REC_SIZE, 0);

    /*** Test Tran Flexi *** /
    {
    int i=12;
    long l=0x12341234;
    char c='z';

        pdebug (("Store String=%d",inStoreTranFlexiData (&obTran, 0x0001, (unsigned char *)"STRING DATA", strlen ("STRING DATA"))));
        pdebug (("Store int=%d",inStoreTranFlexiData (&obTran, 0x0002, (unsigned char *)&i, sizeof (int))));
        pdebug (("Store long=%d",inStoreTranFlexiData (&obTran, 0x0003, (unsigned char *)&l, sizeof (long))));
        pdebug (("Store char=%d",inStoreTranFlexiData (&obTran, 0x0004, (unsigned char *)&c, sizeof (char))));
    }
    **/

    obTran.srBRec.lnMessage = lnTranMsg;
    obTran.inSaveTCTLanguage = inGetLanguageIdx();

    if (srGDS.fExternalEvent)
        vdLoadExternalEventData(&obTran);

    inResult = inInitOper(inOperationCode, inSubOperationCode, &obTran);

    if (inResult == VS_SUCCESS) {
        /** /pdebug(("oper %d",inOperationCode));*/
        /** /pdebug(("sub oper %d",inSubOperationCode));*/
        obTran.srBRec.inCode = inSubOperationCode;
        obTran.inTransactionCode = inSubOperationCode;
        inResult = inRunEngine((short *) pshGetOPTFunctionPtrs(), &obTran);
        /** /pdebug(("Oper inResult = %d",inResult));*/
    }

    if (inResult == VS_SUCCESS) {
        if ((inOperationCode == PRECOMP_OPERATION) || (inOperationCode == OPENTAB_DEL_OPERATION))
            obTran.srBRec.inCode = inSubOperationCode;

        if (inSubOperationCode > 0)
            inResult = inTransactions(&obTran);
    }
    vdSetLanguageIdx(obTran.inSaveTCTLanguage);

    if (srGDS.fExternalEvent && inSubOperationCode > 0)
        vdLoadExternalRespData(&obTran, inResult);

#ifdef BATCH_DEFINED

    /* Close Batch if it has been opened, close it */
    vdCloseDCBatch(&obTran);
    vdCloseTabBatch(&obTran);

#endif // BATCH_DEFINED

    /* VeriFind Support */
    //BT_TRACE (' ', "End Transaction");

    /* clear Merchant ID Table record */
    vdResetMITRec();

    vdDisableClearKey(VS_FALSE);

    pstGetSet_pobTran(&obTran, 2, &inResult);
    vdFree((char *) obTran.srBRec.pchHostData);

    /*** Test Tran Flexi *** /
    {
    int i=12;
    long l=0x12341234;
    char c='z';
    char s[30];

        memset (s, 0, sizeof (s));
        inGetTranFlexiData (&obTran, 0x0001, (unsigned char *)s, sizeof (s));
        pdebug (("String=%s",s));
        inGetTranFlexiData (&obTran, 0x0002, (unsigned char *)&i, sizeof (int));
        pdebug (("Int=%d",i));
        inGetTranFlexiData (&obTran, 0x0003, (unsigned char *)&l, sizeof (long));
        pdebug (("Long=%lx",l));
        inGetTranFlexiData (&obTran, 0x0004, (unsigned char *)&c, sizeof (char));
        pdebug (("Char=%c",c));
    }
    *******/
    vdFree((char *) obTran.pchFlexiData);

    return(BRANCH_EXIT);
} /* End of inOperations () */

/*-------------------------------------------------------------------------
    Function : inCallZontalk
    Description : calls zontalk
    Parameters :
    Returns : failure if ZON fails
    Globals :
    Notes : temporary fix to firmware problem.
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
      0   11/18/98 EW_1       Initial Revision.
--------------------------------------------------------------------------*/
int inCallZontalk(char chZonType) {
    int inRes = 0;
    long lnMsgNo;

#ifdef MOBITEX_DEFINED
    if (srGDS.fWirelessActive)
        inDeInitRadioModem();
#endif

    // This is fixed in the OS now, so no more required.
    /* Until the OS is fixed the application must put the modem in verbose mode */
    /*xmdm_open(&hModem, DEV_MODEM, -1, 30, Rt_1200, Fmt_A7E1);
    strcpy(szCommand, "E1");
       inRes = xhayes_send_cmd(hModem, szCommand);
    if (inRes != (strlen(szCommand) + XHAYES_STRING_FRAME) )
            inRes = VS_ERR;
    SVC_WAIT(100);
    xmdm_close(hModem,0,0);
    */

    // Simulator Error -- SVC_ZONTALK should return an INT but the Simulator returns VOID

	set_font(ASC8X21_VFT);  		//meca 200401023 -- fixed from cashcard O3750 -- download status screen corruption issue

    inRes = SVC_ZONTALK(chZonType);

    if (obDisp.inTerminalType == TERMINAL_OMNI_3200) {
        resetdisplay("k2_6x8.vft", 0); /* set to 3200 default font */
    }

    if (inRes > 0) {
        switch (inRes) {
        case NO_CARRIER:
            lnMsgNo = NO_CARRIER_MSG;
            break;

        case BUSY_DETECT:
            lnMsgNo = BUSY_DETECT_MSG;
            break;

        case NO_DIALTONE:
            lnMsgNo = NO_DIALTONE_MSG;
            break;

        default:
            lnMsgNo = COMMUNICATION_FAILURE_MSG;
        }
        vdDisplayMessageFromFile(lnMsgNo, ERROR_MSG);
    }

    return(inRes);
}

int inRunOperation(TRANSACTION_OBJECT* pobTran,int inOperation) {
    /*
     *      Load OPT Record
     */

    if (inLoadOPTRec(inOperation) != VS_SUCCESS)
    	{

        return(VS_ERR);
    	}
    /*
     *      Run associated operation flow functions
     */

    return(inRunEngine((short *) pshGetOPTFunctionPtrs(), pobTran));
}

int inEditTables(TRANSACTION_OBJECT* pobTran) {
    int inResult;
    char szTableID[3 + 1];
    char szDatFilename[FILENAME_SIZE + 1];
    char szFldFilename[FILENAME_SIZE + 1];

    /*
     *      Reserved, access with MEGA only.
     */
    if (fGetMegaPassword())
        do {
            memset(szTableID, 0, sizeof(szTableID));
            inResult = inEnterWithMessage(ENTER_TABLE_ID_MSG18, SCROLL_DISPLAY_FALSE, szTableID, INPUT_ALNUMS, 3, NULL);
            strcpy(szDatFilename, szTableID);
            strcat(szDatFilename, DAT_SUFFIX);
            strcpy(szFldFilename, STATIC_DATA_PATH);
            strcat(szFldFilename, szTableID);
            strcat(szFldFilename, FLD_SUFFIX);
            if (inResult > VS_ERR) {
                if (inChkFileExist(szDatFilename) == VS_SUCCESS && inChkFileExist(szFldFilename) == VS_SUCCESS) {
                    vdClearNonTitleLines();
                    inResult = inConfRecEdit(szTableID);
                    vdClearNonTitleLines();
                } else
                    inResult = VS_ERR;
            }
            if (inResult == VS_ERR)
                vdDisplayMessageFromFile(EDIT_NOT_ALLOWED21, WARNING_MSG);
        } while (inResult != VS_ESCAPE);
    else {
        /*
         *      KAV - Debug code for testing functionality
         */
#if 1
        vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, WARNING_MSG);
        return(VS_SUCCESS);
#else
        int inReturnValue;
        char buffer[MESSAGE_SIZE + 1];

        /***** ///Added to MENU3200.TXT
            (
                6,
                CONFIG_SERVER_TITLE_MSG15,
                DEBIT_CHOOSE_CARD_MSG,
                LANG_SET_OPERATION_MSG,
                -99
            )
            (   ANY_KEY,        0, SHIFT_MSG, 0, ACCESS_FREELY, NO_PIT_INDEX, FALSE, 1)
            (   ANY_KEY,        0, ABOUT_MSG, 0, ACCESS_FREELY, NO_PIT_INDEX, FALSE, 2)
            (   ANY_KEY,        0, SETUP_MSG, 0, ACCESS_WITH_MANAGER_PASSWORD, NO_PIT_INDEX, FALSE, 3)
            (   ANY_KEY,        0, ONLINE_SALE_ITEM_MSG15, 0, ACCESS_FREELY, NO_PIT_INDEX, FALSE, 4)
            (   ANY_KEY,        0, LOGON_MSG, 0, ACCESS_FREELY, NO_PIT_INDEX, FALSE, 5)
            (   ANY_KEY,        0, CHECK_TRAN_ITEM_MSG15, 0, ACCESS_FREELY, NO_PIT_INDEX, FALSE, 6)
        *****/
        inReturnValue = inDisplayMenu(-99, CHOICES_STYLE);
        clrscr();
        sprintf(buffer, "inReturnValue = %d.", inReturnValue);
        vdDisplayMessage(buffer, STATUS_MSG);
        inWaitKey(inGetIdleTimeOut());

        clrscr();
        inReturnValue = inDisplayMenu(-99, MENUS_STYLE);
        clrscr();
        sprintf(buffer, "inReturnValue = %d.", inReturnValue);
        vdDisplayMessage(buffer, STATUS_MSG);
        inWaitKey(inGetIdleTimeOut());

        vdSetMenuFont();
        clrscr();
        inReturnValue = inDisplayMenu(-99, MENUS_STYLE);
        vdSetActionFont();
        clrscr();
        sprintf(buffer, "inReturnValue = %d.", inReturnValue);
        vdDisplayMessage(buffer, STATUS_MSG);
        inWaitKey(inGetIdleTimeOut());
#endif
    }

    return(VS_SUCCESS);
}

int inNotAvailableOperation(TRANSACTION_OBJECT* pobTran) {
    pdebug(("--inNotAvailableOperation--"));

    vdDisplayErrorMessage(FUNCTION_NOT_FOUND_MSG16);

    return(BRANCH_EXIT);
}

int OPERATE_CODE_CHECK(char* a,char* b,short* c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}

#undef VSOPER_C

